
package datagraphics;

import java.awt.Dimension;

import java.io.IOException;
import triviaException.TriviaException;

import database.*;

import java.util.Iterator;
import java.util.LinkedList;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;

/**
 * Main de la aplicacion
 * @author Grupo 11 de Programacion Orientada a Objetos
 *
 */

public class MainMenu extends javax.swing.JFrame {
    TriviaDbase tdbase = null;
    QuestionVisitor qvisitor = null;
    GameUser guser = null;
    Iterator<Question> qiter = null;
    Question q, liveEditq;
    BooleanQuestion auxBool = null;
    NumericQuestion auxNum = null;
    SimpleQuestion auxSim = null;
    MultipleQuestion auxMul = null;
    Boolean[] correctAnswers = null;
    int qnumber = 0;
    EditPanel edp = null;
    JScrollPane jscroll = null;
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** Creates new form MainMenu 
	 * @throws TriviaException 
	 * @throws IOException */
    public MainMenu() throws TriviaException, NumberFormatException, IOException {
        initComponents();
        tdbase = new TriviaDbase();
        
        try {
        	tdbase.loadQuestions();
        }
        catch (TriviaException e) {
    		showCantPlayDialog(e.getMessage().toString() + ". Program Terminated");
    		e.printStackTrace();
    		System.exit(1);
        } finally {
	        initHighScores();
	        jQOptions.setLayout(new ModifiedFlowLayout());
	        jAnswers.setLayout(new BoxLayout(jAnswers, BoxLayout.PAGE_AXIS));
	        qvisitor = new QuestionVisitor(jQOptions);
	        
	        initEditPanel();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * NOTE: CODE GENERATED BY NETBEANS!\
     */
    @SuppressWarnings({ "unchecked", "deprecation" })
    
    private void initComponents() {

        EditCategory = new javax.swing.ButtonGroup();
        BooleanAnswer = new javax.swing.ButtonGroup();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jMainMenu = new javax.swing.JInternalFrame();
        jLabel1 = new javax.swing.JLabel();
        jNewTrivia = new javax.swing.JButton();
        jEditTrivia = new javax.swing.JButton();
        jHighScoresTrivia = new javax.swing.JButton();
        jQuestions = new javax.swing.JInternalFrame();
        jQuestionPane = new javax.swing.JPanel();
        jQtext = new javax.swing.JLabel();
        jQNext = new javax.swing.JButton();
        jQOptions = new javax.swing.JPanel();
        jSeparator3 = new javax.swing.JSeparator();
        jHighScores = new javax.swing.JInternalFrame();
        jTitleHscore = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jComboBox1 = new javax.swing.JComboBox();
        jSeparator2 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jScoreTable = new javax.swing.JTable();
        jExitScores = new javax.swing.JButton();
        jGameInfo = new javax.swing.JInternalFrame();
        jPanel1 = new javax.swing.JPanel();
        jUsrInfoImg = new javax.swing.JLabel();
        jUsrName = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jInputName = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        jLevel = new javax.swing.JComboBox();
        jStartGame = new javax.swing.JButton();
        jWarning = new javax.swing.JLabel();
        jGameCancel = new javax.swing.JButton();
        jResults = new javax.swing.JInternalFrame();
        jAnswerContainer = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        jLabel25 = new javax.swing.JLabel();
        jFinalScore = new javax.swing.JLabel();
        jSeparator5 = new javax.swing.JSeparator();
        jAnswers = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jEditQuestions = new javax.swing.JInternalFrame();
        jLabel5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jPanel3 = new javax.swing.JPanel();
        jNewQuestion = new javax.swing.JButton();
        jEditQuestion = new javax.swing.JButton();
        jEraseQuestion = new javax.swing.JButton();
        jEditFinish = new javax.swing.JButton();
        jPageBack = new javax.swing.JButton();
        jNextPage = new javax.swing.JButton();
        jEditContainer = new javax.swing.JPanel();
        jBoolMod = new javax.swing.JInternalFrame();
        jQBoolean = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jBoolQTxt = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jBoolQTrue = new javax.swing.JRadioButton();
        jBoolQFalse = new javax.swing.JRadioButton();
        jLabel8 = new javax.swing.JLabel();
        jBoolCombo = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jBoolScore = new javax.swing.JFormattedTextField();
        jBoolSave = new javax.swing.JButton();
        jBoolCancel = new javax.swing.JButton();
        jNumMod = new javax.swing.JInternalFrame();
        jQNum = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jNumQTxt = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jNumAnswer = new javax.swing.JFormattedTextField();
        jLabel12 = new javax.swing.JLabel();
        jNumCombo = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jNumScore = new javax.swing.JFormattedTextField();
        jNumSave = new javax.swing.JButton();
        jNumCancel = new javax.swing.JButton();
        jSimpleMod = new javax.swing.JInternalFrame();
        jQSimple = new javax.swing.JPanel();
        jSimpleQTxt = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jSimpleAnswer = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jSimpleCombo = new javax.swing.JComboBox();
        jSimpleScore = new javax.swing.JFormattedTextField();
        jLabel17 = new javax.swing.JLabel();
        jSimpleSave = new javax.swing.JButton();
        jSimpleCancel = new javax.swing.JButton();
        jMulti1Mod = new javax.swing.JInternalFrame();
        jQMultiple = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jMulti1QTxt = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jMulti1Combo = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        jMulti1Score = new javax.swing.JFormattedTextField();
        jLabel19 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jMulti1List1 = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        jMulti1List2 = new javax.swing.JList();
        jMulti1Add = new javax.swing.JButton();
        jMulti1Modify = new javax.swing.JButton();
        jMulti1Move = new javax.swing.JButton();
        jMulti1Delete = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        jMulti1DelAns = new javax.swing.JButton();
        jMulti1Save = new javax.swing.JButton();
        jMulti1Cancel = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jDesktopPane1.setBackground(new java.awt.Color(240, 240, 240));

        jMainMenu.setVisible(true);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/datagraphics/trivia.png")));
        jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jNewTrivia.setText("New Trivia");
        jNewTrivia.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jNewTriviaActionPerformed(evt);
            }
        });

        jEditTrivia.setText("Edit Trivia");
        jEditTrivia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jEditTriviaActionPerformed(evt);
            }
        });

        jHighScoresTrivia.setText("View Highscores");
        jHighScoresTrivia.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jHighScoresTriviaActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jMainMenuLayout = new org.jdesktop.layout.GroupLayout(
        jMainMenu.getContentPane());
        
        jMainMenu.getContentPane().setLayout(jMainMenuLayout);
        jMainMenuLayout.setHorizontalGroup(
            jMainMenuLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jMainMenuLayout.createSequentialGroup()
                .add(jMainMenuLayout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jMainMenuLayout.createSequentialGroup()
                        .add(78, 78, 78)
                        .add(jLabel1))
                    .add(jMainMenuLayout.createSequentialGroup()
                        .add(117, 117, 117)
                        .add(jMainMenuLayout.createParallelGroup(
                        org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jHighScoresTrivia, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                            org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jEditTrivia, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                            org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jNewTrivia, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                            org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(91, Short.MAX_VALUE))
        );
        jMainMenuLayout.setVerticalGroup(
            jMainMenuLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jMainMenuLayout.createSequentialGroup()
                .add(jLabel1)
                .add(18, 18, 18)
                .add(jNewTrivia)
                .add(18, 18, 18)
                .add(jEditTrivia)
                .add(18, 18, 18)
                .add(jHighScoresTrivia)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jMainMenu.setBounds(0, 0, 360, 330);
        jDesktopPane1.add(jMainMenu, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jQuestions.setResizable(true);

        jQuestionPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Questions"));

        jQtext.setFont(new java.awt.Font("Tahoma", 0, 14));
        jQtext.setText("Question text");

        jQNext.setText("Next >");
        jQNext.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
					jQNextActionPerformed(evt);
				} catch (TriviaException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        });

        org.jdesktop.layout.GroupLayout jQOptionsLayout = 
        new org.jdesktop.layout.GroupLayout(jQOptions);
        jQOptions.setLayout(jQOptionsLayout);
        jQOptionsLayout.setHorizontalGroup(
            jQOptionsLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            	.add(0, 478, Short.MAX_VALUE)
        );
        jQOptionsLayout.setVerticalGroup(
            jQOptionsLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            	.add(0, 145, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout jQuestionPaneLayout = 
        new org.jdesktop.layout.GroupLayout(jQuestionPane);
        	jQuestionPane.setLayout(jQuestionPaneLayout);
        jQuestionPaneLayout.setHorizontalGroup(
            jQuestionPaneLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            	.add(jQuestionPaneLayout.createSequentialGroup()
            			.addContainerGap()
                .add(jQuestionPaneLayout.createParallelGroup(
                org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jQNext)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, 
                    jQuestionPaneLayout.createSequentialGroup()
                        .add(jQuestionPaneLayout.createParallelGroup(
                        org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, 
                            jQOptions, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                            org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jQtext)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jSeparator3, 
                            org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE))
                        .addContainerGap())))
        );
        jQuestionPaneLayout.setVerticalGroup(
            jQuestionPaneLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQuestionPaneLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQtext)
                .add(4, 4, 4)
                .add(jSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jQOptions, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jQNext)
                .add(63, 63, 63))
        );

        org.jdesktop.layout.GroupLayout jQuestionsLayout = 
        new org.jdesktop.layout.GroupLayout(jQuestions.getContentPane());
        jQuestions.getContentPane().setLayout(jQuestionsLayout);
        jQuestionsLayout.setHorizontalGroup(
            jQuestionsLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQuestionsLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQuestionPane, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jQuestionsLayout.setVerticalGroup(
            jQuestionsLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQuestionsLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQuestionPane, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                Short.MAX_VALUE)
                .addContainerGap())
        );

        jQuestions.setBounds(0, 0, 540, 380);
        jDesktopPane1.add(jQuestions, 
        javax.swing.JLayeredPane.DEFAULT_LAYER);

        jHighScores.addComponentListener(new ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jHighScoresComponentShown(evt);
            }
        });

        jTitleHscore.setFont(new java.awt.Font("Tahoma", 0, 24));
        jTitleHscore.setText("Easy - HighScores");

        jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(
        new String[] { "Easy", "Medium", "Hard" }));
        jComboBox1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jScoreTable.setFont(new java.awt.Font("Tahoma", 0, 12));
        jScoreTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Name", "Score"
            }
        ) {
            /**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScoreTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jScoreTable);
        jScoreTable.getColumnModel().getColumn(0).setResizable(false);
        jScoreTable.getColumnModel().getColumn(1).setResizable(false);

        jExitScores.setText("Exit");
        jExitScores.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jExitScoresActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jHighScoresLayout = 
        new org.jdesktop.layout.GroupLayout(jHighScores.getContentPane());
        jHighScores.getContentPane().setLayout(jHighScoresLayout);
        jHighScoresLayout.setHorizontalGroup(
            jHighScoresLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jHighScoresLayout.createSequentialGroup()
                .addContainerGap()
                .add(jHighScoresLayout.createParallelGroup(
                org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jSeparator1, 
                    org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .add(jTitleHscore)
                    .add(jComboBox1, 
                    org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                   83, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jHighScoresLayout.createSequentialGroup()
                        .add(64, 64, 64)
                        .add(jHighScoresLayout.createParallelGroup(
                        org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jExitScores)
                            .add(jHighScoresLayout.createSequentialGroup()
                                .add(jScrollPane1, 
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                                184, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(66, 66, 66)
                                .add(jSeparator2, 
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        jHighScoresLayout.setVerticalGroup(
            jHighScoresLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jHighScoresLayout.createSequentialGroup()
                .addContainerGap()
                .add(jTitleHscore)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(jHighScoresLayout.createParallelGroup(
                org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jHighScoresLayout.createSequentialGroup()
                        .add(41, 41, 41)
                        .add(jSeparator2, 
                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                        10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jHighScoresLayout.createSequentialGroup()
                        .add(18, 18, 18)
                        .add(jScrollPane1, 
                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                        189, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(27, 27, 27)
                .add(jExitScores)
                .addContainerGap())
        );

        jHighScores.setBounds(0, 0, 390, 410);
        jDesktopPane1.add(jHighScores, 
        javax.swing.JLayeredPane.DEFAULT_LAYER);

        jUsrInfoImg.setIcon(
        new javax.swing.ImageIcon(getClass().getResource(
        "/datagraphics/usrinfo.png")));

        jUsrName.setFont(new java.awt.Font("Tahoma", 0, 14));
        jUsrName.setText("Your Name:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel3.setForeground(new java.awt.Color(102, 102, 102));
        jLabel3.setText("(20 characters max)");

        jInputName.setColumns(3);
        try {
            jInputName.setFormatterFactory(
            new javax.swing.text.DefaultFormatterFactory(
            new javax.swing.text.MaskFormatter("********************")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jInputName.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jInputNameActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel4.setText("Choose game difficulty:");

        jLevel.setModel(new javax.swing.DefaultComboBoxModel(
        		new String[] { "easy", "medium", "hard" }));

        jStartGame.setText("Start!");
        jStartGame.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jStartGameActionPerformed(evt);
            }
        });

        jWarning.setForeground(new java.awt.Color(255, 0, 0));

        jGameCancel.setText("Cancel");
        jGameCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jGameCancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = 
        new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
            .add(jPanel1Layout.createParallelGroup(
            	org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jPanel1Layout.createParallelGroup(
                    	org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jLevel, 
                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                       78, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jPanel1Layout.createSequentialGroup()
                            .add(jPanel1Layout.createParallelGroup(
                        	org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jUsrName)
                                .add(14, 14, 14)
                                .add(jInputName, 
                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                                154, Short.MAX_VALUE))
                            .add(jPanel1Layout.createSequentialGroup()
                                    .add(jLabel3)
                                    .addPreferredGap(
                                    org.jdesktop.layout.LayoutStyle.RELATED, 
                                    152, Short.MAX_VALUE))
                                .add(jLabel4))
                            .add(18, 18, 18)
                            .add(jUsrInfoImg, 
                            org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                            154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(80, 80, 80)
                        .add(jPanel1Layout.createParallelGroup(
                        	org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(43, 43, 43)
                                .add(jStartGame)
                                .add(18, 18, 18)
                                .add(jGameCancel))
                            .add(jWarning))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(
            		org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(36, 36, 36)
                        .add(jPanel1Layout.createParallelGroup(
                        		org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jUsrName)
                            .add(jInputName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                            org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel3)
                        .add(50, 50, 50)
                        .add(jLabel4)
                        .add(18, 18, 18)
                        .add(jLevel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jUsrInfoImg)))
                .add(39, 39, 39)
                .add(jPanel1Layout.createParallelGroup(
                org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jStartGame)
                    .add(jGameCancel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jWarning)
                .add(29, 29, 29))
        );

        org.jdesktop.layout.GroupLayout jGameInfoLayout = 
        new org.jdesktop.layout.GroupLayout(jGameInfo.getContentPane());
        jGameInfo.getContentPane().setLayout(jGameInfoLayout);
        jGameInfoLayout.setHorizontalGroup(
            jGameInfoLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jGameInfoLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                Short.MAX_VALUE)
                .addContainerGap())
        );
        jGameInfoLayout.setVerticalGroup(
            jGameInfoLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jGameInfoLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                Short.MAX_VALUE)
                .addContainerGap())
        );

        jGameInfo.setBounds(0, 0, 470, 340);
        jDesktopPane1.add(jGameInfo, 
        javax.swing.JLayeredPane.DEFAULT_LAYER);

        jAnswerContainer.setAutoscrolls(true);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel2.setText("Resultados:");

        jLabel25.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel25.setText("Su Puntaje:");

        jFinalScore.setText("jLabel26");

        org.jdesktop.layout.GroupLayout jAnswersLayout = new org.jdesktop.layout.GroupLayout(jAnswers);
        jAnswers.setLayout(jAnswersLayout);
        jAnswersLayout.setHorizontalGroup(
            jAnswersLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 628, Short.MAX_VALUE)
        );
        jAnswersLayout.setVerticalGroup(
            jAnswersLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 302, Short.MAX_VALUE)
        );

        jButton1.setText("Finish!");
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jAnswerContainerLayout = 
        new org.jdesktop.layout.GroupLayout(jAnswerContainer);
        jAnswerContainer.setLayout(jAnswerContainerLayout);
        jAnswerContainerLayout.setHorizontalGroup(
            jAnswerContainerLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jAnswerContainerLayout.createSequentialGroup()
                .addContainerGap()
                .add(jAnswerContainerLayout.createParallelGroup(
                	org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jAnswerContainerLayout.createSequentialGroup()
                        .add(jAnswers, 
                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                        Short.MAX_VALUE)
                        .addContainerGap())
                    .add(jAnswerContainerLayout.createParallelGroup(
                    		org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jAnswerContainerLayout.createSequentialGroup()
                            .add(jLabel2)
                            .add(506, 506, 506))
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, 
                        	jAnswerContainerLayout.createSequentialGroup()
                            .add(jSeparator4, 
                            org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                            606, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(23, 23, 23)))
                    .add(jAnswerContainerLayout.createSequentialGroup()
                        .add(jSeparator5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                        628, Short.MAX_VALUE)
                        .addContainerGap())
                    .add(jAnswerContainerLayout.createSequentialGroup()
                        .add(jLabel25)
                        .add(18, 18, 18)
                        .add(jFinalScore)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 
                        312, Short.MAX_VALUE)
                        .add(jButton1)
                        .add(103, 103, 103))))
        );
        jAnswerContainerLayout.setVerticalGroup(
            jAnswerContainerLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jAnswerContainerLayout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                		10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jAnswers, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                		org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(18, 18, 18)
                .add(jSeparator5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(1, 1, 1)
                .add(jAnswerContainerLayout.createParallelGroup(
                org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel25)
                    .add(jFinalScore)
                    .add(jButton1))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout jResultsLayout = 
        new org.jdesktop.layout.GroupLayout(jResults.getContentPane());
        jResults.getContentPane().setLayout(jResultsLayout);
        jResultsLayout.setHorizontalGroup(
            jResultsLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jResultsLayout.createSequentialGroup()
                .addContainerGap()
                .add(jAnswerContainer, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                565, Short.MAX_VALUE)
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jResultsLayout.setVerticalGroup(
            jResultsLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jResultsLayout.createSequentialGroup()
                .addContainerGap()
                .add(jAnswerContainer, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                Short.MAX_VALUE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jResults.setBounds(0, 0, 600, 500);
        jDesktopPane1.add(jResults, 
        javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel5.setFont(new java.awt.Font("Bitstream Vera Sans", 0, 14));
        jLabel5.setText("Trivia Config");

        jPanel2.setBorder(
        javax.swing.BorderFactory.createTitledBorder("Choose Category:"));

        EditCategory.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("easy");
        jRadioButton1.setNextFocusableComponent(jRadioButton2);
        jRadioButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
					jRadioButton1ActionPerformed(evt);
				} catch (TriviaException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        });

        EditCategory.add(jRadioButton2);
        jRadioButton2.setText("medium");
        jRadioButton2.setNextFocusableComponent(jRadioButton3);
        jRadioButton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
					jRadioButton2ActionPerformed(evt);
				} catch (TriviaException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        });

        EditCategory.add(jRadioButton3);
        jRadioButton3.setText("hard");
        jRadioButton3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
					jRadioButton3ActionPerformed(evt);
				} catch (TriviaException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        });

        org.jdesktop.layout.GroupLayout jPanel2Layout = 
        	new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(
            		org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(34, 34, 34)
                .add(jRadioButton1)
                .add(41, 41, 41)
                .add(jRadioButton2)
                .add(50, 50, 50)
                .add(jRadioButton3)
                .addContainerGap(48, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(
            		org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(22, 22, 22)
                .add(jPanel2Layout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jRadioButton1)
                    .add(jRadioButton2)
                    .add(jRadioButton3))
                .addContainerGap(
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                Short.MAX_VALUE))
        );

        jNewQuestion.setText("New");
        jNewQuestion.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jNewQuestionActionPerformed(evt);
            }
        });

        jEditQuestion.setText("Edit");
        jEditQuestion.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
            	Question liveq = edp.getQuestionSelected();
            	if (liveq != null)
            		jEditQuestionActionPerformed(evt, liveq);
            }
        });

        jEraseQuestion.setText("Delete");
        jEraseQuestion.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jEraseQuestionActionPerformed(evt);
            }
        });

        jEditFinish.setText("Finish Edit");
        jEditFinish.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jEditFinishActionPerformed(evt);
            }
        });

        jPageBack.setText("<<");
        jPageBack.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jPageBackActionPerformed(evt);
            }
        });

        jNextPage.setText(">>");
        jNextPage.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jNextPageActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout = 
        	new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jNewQuestion)
                .add(18, 18, 18)
                .add(jEditQuestion)
                .add(18, 18, 18)
                .add(jEraseQuestion)
                .add(54, 54, 54)
                .add(jPageBack)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jNextPage)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 154, Short.MAX_VALUE)
                .add(jEditFinish)
                .add(45, 45, 45))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, 
            jPanel3Layout.createSequentialGroup()
                .addContainerGap(
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                Short.MAX_VALUE)
                .add(jPanel3Layout.createParallelGroup(
                	org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jNewQuestion)
                    .add(jEditQuestion)
                    .add(jEraseQuestion)
                    .add(jEditFinish)
                    .add(jPageBack)
                    .add(jNextPage))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout jEditContainerLayout = 
        	new org.jdesktop.layout.GroupLayout(jEditContainer);
        jEditContainer.setLayout(jEditContainerLayout);
        jEditContainerLayout.setHorizontalGroup(
            jEditContainerLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 552, Short.MAX_VALUE)
        );
        jEditContainerLayout.setVerticalGroup(
            jEditContainerLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 212, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout jEditQuestionsLayout = 
        new org.jdesktop.layout.GroupLayout(jEditQuestions.getContentPane());
        jEditQuestions.getContentPane().setLayout(jEditQuestionsLayout);
        jEditQuestionsLayout.setHorizontalGroup(
            jEditQuestionsLayout.createParallelGroup(
            	org.jdesktop.layout.GroupLayout.LEADING)
            .add(jEditQuestionsLayout.createSequentialGroup()
                .add(jEditQuestionsLayout.createParallelGroup(
                	org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jEditQuestionsLayout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(jEditQuestionsLayout.createParallelGroup(
                        		org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel2, 
                            	org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                            	org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                            	org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel5)
                            .add(jEditContainer, 
                            org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                            org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                            org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jEditQuestionsLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel3, 
                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                        Short.MAX_VALUE)))
                .addContainerGap())
        );
        jEditQuestionsLayout.setVerticalGroup(
            jEditQuestionsLayout.createParallelGroup(
            		org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, 
            		jEditQuestionsLayout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel5)
                .add(28, 28, 28)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jEditContainer, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(54, 54, 54))
        );

        jEditQuestions.setBounds(0, 0, 630, 470);
        jDesktopPane1.add(jEditQuestions, 
        javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel6.setText("Question:");

        jLabel7.setText("Select Answer:");

        BooleanAnswer.add(jBoolQTrue);
        jBoolQTrue.setText("True");
        jBoolQTrue.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jBoolQTrueActionPerformed(evt);
            }
        });

        BooleanAnswer.add(jBoolQFalse);
        jBoolQFalse.setText("False");
        jBoolQFalse.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jBoolQFalseActionPerformed(evt);
            }
        });

        jLabel8.setText("Select Question Difficulty:");

        jBoolCombo.setModel(new javax.swing.DefaultComboBoxModel(
        new String[] { "easy", "medium", "hard" }));
        jBoolCombo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jBoolComboActionPerformed(evt);
            }
        });

        jLabel9.setText("Select Question Score:");

        jBoolScore.setFormatterFactory(
        new javax.swing.text.DefaultFormatterFactory(
        		new javax.swing.text.NumberFormatter(
        				new java.text.DecimalFormat("#0"))));

        jBoolSave.setText("Save");
        jBoolSave.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
					jBoolSaveActionPerformed(evt);
				} catch (IOException e) {
					System.err.println(e.getMessage());
				}
            }
        });

        jBoolCancel.setText("Cancel");
        jBoolCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jBoolCancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jQBooleanLayout = 
        new org.jdesktop.layout.GroupLayout(jQBoolean);
        jQBoolean.setLayout(jQBooleanLayout);
        jQBooleanLayout.setHorizontalGroup(
            jQBooleanLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQBooleanLayout.createSequentialGroup()
                .add(jLabel6)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jBoolQTxt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                421, Short.MAX_VALUE))
            .add(jQBooleanLayout.createSequentialGroup()
                .add(jLabel7)
                .add(18, 18, 18)
                .add(jBoolQTrue)
                .add(18, 18, 18)
                .add(jBoolQFalse)
                .add(144, 144, 144))
            .add(jQBooleanLayout.createSequentialGroup()
                .add(jQBooleanLayout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel8)
                    .add(jLabel9))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jQBooleanLayout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, 
                    jBoolScore, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                    101, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jBoolCombo, 
                    org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                    org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                    org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(218, 218, 218))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, 
            		jQBooleanLayout.createSequentialGroup()
                .addContainerGap(340, Short.MAX_VALUE)
                .add(jBoolSave)
                .add(18, 18, 18)
                .add(jBoolCancel)
                .add(29, 29, 29))
        );
        jQBooleanLayout.setVerticalGroup(
            jQBooleanLayout.createParallelGroup(
            		org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQBooleanLayout.createSequentialGroup()
                .add(jQBooleanLayout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(jBoolQTxt, 
                    	org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                    	org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                    	org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(41, 41, 41)
                .add(jQBooleanLayout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(jBoolQTrue)
                    .add(jBoolQFalse))
                .add(44, 44, 44)
                .add(jQBooleanLayout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel8)
                    .add(jBoolCombo, 
                    org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                    22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(42, 42, 42)
                .add(jQBooleanLayout.createParallelGroup(
                	org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel9)
                    .add(jBoolScore, 
                    org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                    22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 
                106, Short.MAX_VALUE)
                .add(jQBooleanLayout.createParallelGroup(
                	org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jBoolCancel)
                    .add(jBoolSave)))
        );

        org.jdesktop.layout.GroupLayout jBoolModLayout = 
        	new org.jdesktop.layout.GroupLayout(jBoolMod.getContentPane());
        jBoolMod.getContentPane().setLayout(jBoolModLayout);
        jBoolModLayout.setHorizontalGroup(
            jBoolModLayout.createParallelGroup(
            		org.jdesktop.layout.GroupLayout.LEADING)
            .add(jBoolModLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQBoolean, 
                	org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jBoolModLayout.setVerticalGroup(
            jBoolModLayout.createParallelGroup(
            	org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, 
            	jBoolModLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQBoolean, 
                	org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                	org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                	Short.MAX_VALUE)
                .addContainerGap())
        );

        jBoolMod.setBounds(0, 0, 520, 410);
        jDesktopPane1.add(jBoolMod, 
        	javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel10.setText("Question:");

        jLabel11.setText("Set Answer:");

        jNumAnswer.setFormatterFactory(
        new javax.swing.text.DefaultFormatterFactory(
        new javax.swing.text.NumberFormatter(
        new java.text.DecimalFormat("#0"))));

        jLabel12.setText("Select Question Difficulty:");

        jNumCombo.setModel(new javax.swing.DefaultComboBoxModel(
        new String[] { "easy", "medium", "hard" }));
        jNumCombo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jNumComboActionPerformed(evt);
            }
        });

        jLabel13.setText("Select Question Score:");

        jNumScore.setFormatterFactory(
        new javax.swing.text.DefaultFormatterFactory(
        new javax.swing.text.NumberFormatter(
        new java.text.DecimalFormat("#0"))));

        jNumSave.setText("Save");
        jNumSave.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
					jNumSaveActionPerformed(evt);
				} catch (IOException e) {
					System.err.println(e.getMessage());
				}
            }
        });

        jNumCancel.setText("Cancel");
        jNumCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jNumCancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jQNumLayout = 
        new org.jdesktop.layout.GroupLayout(jQNum);
        jQNum.setLayout(jQNumLayout);
        jQNumLayout.setHorizontalGroup(
            jQNumLayout.createParallelGroup(
            org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQNumLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQNumLayout.createParallelGroup(
                	org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jQNumLayout.createSequentialGroup()
                        .add(jQNumLayout.createParallelGroup(
                        	org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jQNumLayout.createSequentialGroup()
                                .add(jQNumLayout.createParallelGroup(
                                org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel11)
                                    .add(jLabel10))
                                .addPreferredGap(
                                org.jdesktop.layout.LayoutStyle.RELATED, 
                                12, Short.MAX_VALUE)
                                .add(jQNumLayout.createParallelGroup(
                                org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jNumQTxt, 
                                    org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                                    405, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jQNumLayout.createParallelGroup(
                                    org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(jNumAnswer, 
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                                       195, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(jQNumLayout.createParallelGroup(
                                        org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(jNumScore, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                                            109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(jNumCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                                            org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                                            org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                            .add(jLabel12)
                            .add(jLabel13))
                        .addContainerGap(19, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, 
                    		jQNumLayout.createSequentialGroup()
                        .add(jNumSave)
                        .add(18, 18, 18)
                        .add(jNumCancel)
                        .add(27, 27, 27))))
        );
        jQNumLayout.setVerticalGroup(
            jQNumLayout.createParallelGroup(
            		org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQNumLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQNumLayout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel10)
                    .add(jNumQTxt, 
                    org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 
                    org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 
                    org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(46, 46, 46)
                .add(jQNumLayout.createParallelGroup(
                		org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(jNumAnswer, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(57, 57, 57)
                .add(jQNumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel12)
                    .add(jNumCombo, 0, 0, Short.MAX_VALUE))
                .add(31, 31, 31)
                .add(jQNumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel13)
                    .add(jNumScore, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 34, Short.MAX_VALUE)
                .add(jQNumLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jNumSave)
                    .add(jNumCancel)))
        );

        org.jdesktop.layout.GroupLayout jNumModLayout = new org.jdesktop.layout.GroupLayout(jNumMod.getContentPane());
        jNumMod.getContentPane().setLayout(jNumModLayout);
        jNumModLayout.setHorizontalGroup(
            jNumModLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jNumModLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQNum, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jNumModLayout.setVerticalGroup(
            jNumModLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jNumModLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQNum, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jNumMod.setBounds(0, 0, 550, 360);
        jDesktopPane1.add(jNumMod, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel14.setText("Question:");

        jLabel15.setText("Set Answer:");

        jLabel16.setText("Select Question Difficulty:");

        jSimpleCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "easy", "medium", "hard" }));
        jSimpleCombo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jSimpleComboActionPerformed(evt);
            }
        });

        jSimpleScore.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));

        jLabel17.setText("Select Question Score:");

        jSimpleSave.setText("Save");
        jSimpleSave.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
					jSimpleSaveActionPerformed(evt);
				} catch (IOException e) {
					System.err.println(e.getMessage());
				}
            }
        });

        jSimpleCancel.setText("Cancel");
        jSimpleCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jSimpleCancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jQSimpleLayout = new org.jdesktop.layout.GroupLayout(jQSimple);
        jQSimple.setLayout(jQSimpleLayout);
        jQSimpleLayout.setHorizontalGroup(
            jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQSimpleLayout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jQSimpleLayout.createSequentialGroup()
                        .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jQSimpleLayout.createSequentialGroup()
                                .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel16)
                                    .add(jLabel17))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(jSimpleCombo, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(jSimpleScore, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                            .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jQSimpleLayout.createSequentialGroup()
                                    .add(jLabel14)
                                    .add(27, 27, 27)
                                    .add(jSimpleQTxt))
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jQSimpleLayout.createSequentialGroup()
                                    .add(jLabel15)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jSimpleAnswer, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 399, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                        .add(25, 25, 25))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jQSimpleLayout.createSequentialGroup()
                        .add(jSimpleSave)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jSimpleCancel)
                        .add(52, 52, 52))))
        );
        jQSimpleLayout.setVerticalGroup(
            jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQSimpleLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel14)
                    .add(jSimpleQTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(30, 30, 30)
                .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel15)
                    .add(jSimpleAnswer, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(72, 72, 72)
                .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel16)
                    .add(jSimpleCombo, 0, 0, Short.MAX_VALUE))
                .add(35, 35, 35)
                .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel17)
                    .add(jSimpleScore, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(41, 41, 41)
                .add(jQSimpleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jSimpleSave)
                    .add(jSimpleCancel)))
        );

        org.jdesktop.layout.GroupLayout jSimpleModLayout = new org.jdesktop.layout.GroupLayout(jSimpleMod.getContentPane());
        jSimpleMod.getContentPane().setLayout(jSimpleModLayout);
        jSimpleModLayout.setHorizontalGroup(
            jSimpleModLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jSimpleModLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQSimple, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jSimpleModLayout.setVerticalGroup(
            jSimpleModLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jSimpleModLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQSimple, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jSimpleMod.setBounds(0, 0, 550, 370);
        jDesktopPane1.add(jSimpleMod, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jQMultiple.setPreferredSize(new java.awt.Dimension(624, 522));

        jLabel18.setText("Question:");

        jLabel20.setText("Select Question Difficulty:");

        jMulti1Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "easy", "medium", "hard" }));
        jMulti1Combo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMulti1ComboActionPerformed(evt);
            }
        });

        jLabel21.setText("Select Question Score:");

        jMulti1Score.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));

        jLabel19.setText("Mulitple Choices:");

        jMulti1List1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jMulti1List1.setToolTipText("Click an item and decide what to do...");
        jScrollPane2.setViewportView(jMulti1List1);

        jMulti1List2.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jMulti1List2.setToolTipText("Click an item and decide what to do...");
        jScrollPane3.setViewportView(jMulti1List2);

        jMulti1Add.setText("Add");
        jMulti1Add.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMulti1AddActionPerformed(evt);
            }
        });

        jMulti1Modify.setText("Modify");
        jMulti1Modify.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMulti1ModifyActionPerformed(evt);
            }
        });

        jMulti1Move.setText("Move to Answers");
        jMulti1Move.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMulti1MoveActionPerformed(evt);
            }
        });

        jMulti1Delete.setText("Delete");
        jMulti1Delete.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMulti1DeleteActionPerformed(evt);
            }
        });

        jLabel22.setText("Answers:");

        jMulti1DelAns.setText("Delete Answer");
        jMulti1DelAns.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMulti1DelAnsActionPerformed(evt);
            }
        });

        jMulti1Save.setText("Save");
        jMulti1Save.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
					jMulti1SaveActionPerformed(evt);
				} catch (IOException e) {
					System.err.println(e.getMessage());
				}
            }
        });

        jMulti1Cancel.setText("Cancel");
        jMulti1Cancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMulti1CancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jQMultipleLayout = new org.jdesktop.layout.GroupLayout(jQMultiple);
        jQMultiple.setLayout(jQMultipleLayout);
        jQMultipleLayout.setHorizontalGroup(
            jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQMultipleLayout.createSequentialGroup()
                .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jQMultipleLayout.createSequentialGroup()
                        .addContainerGap(462, Short.MAX_VALUE)
                        .add(jMulti1Save, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 68, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jMulti1Cancel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jQMultipleLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel22)
                            .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel19)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jQMultipleLayout.createSequentialGroup()
                                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 448, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                        .add(jMulti1Delete, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .add(jMulti1Move, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .add(jMulti1Modify, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .add(jMulti1Add, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jQMultipleLayout.createSequentialGroup()
                                    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 448, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jMulti1DelAns, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .add(jQMultipleLayout.createSequentialGroup()
                                .add(jLabel18)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jMulti1QTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 517, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jQMultipleLayout.createSequentialGroup()
                                .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel20)
                                    .add(jLabel21))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(jMulti1Score)
                                    .add(jMulti1Combo, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
                .addContainerGap(46, Short.MAX_VALUE))
        );
        jQMultipleLayout.setVerticalGroup(
            jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jQMultipleLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel18)
                    .add(jMulti1QTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel19)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jQMultipleLayout.createSequentialGroup()
                        .add(jMulti1Add)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jMulti1Modify)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jMulti1Move)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jMulti1Delete))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(29, 29, 29)
                .add(jLabel22)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jQMultipleLayout.createSequentialGroup()
                        .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 108, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jMulti1Combo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel20))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel21)
                            .add(jMulti1Score, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jMulti1DelAns))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jQMultipleLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jMulti1Save)
                    .add(jMulti1Cancel))
                .add(36, 36, 36))
        );

        org.jdesktop.layout.GroupLayout jMulti1ModLayout = new org.jdesktop.layout.GroupLayout(jMulti1Mod.getContentPane());
        jMulti1Mod.getContentPane().setLayout(jMulti1ModLayout);
        jMulti1ModLayout.setHorizontalGroup(
            jMulti1ModLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jMulti1ModLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQMultiple, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
                .addContainerGap())
        );
        jMulti1ModLayout.setVerticalGroup(
            jMulti1ModLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jMulti1ModLayout.createSequentialGroup()
                .addContainerGap()
                .add(jQMultiple, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 489, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jMulti1Mod.setBounds(0, 0, 690, 540);
        jDesktopPane1.add(jMulti1Mod, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jMenu1.setText("File");
        jMenu1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("New Game");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Quit");
        jMenuItem2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Edit Trivia");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("View");

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("View Highscores");
        jMenuItem4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem4);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jDesktopPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 720, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jDesktopPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 575, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }
    // END OF NETBEANS CODE 

    private void jNewTriviaActionPerformed(ActionEvent evt) {
        jMainMenu.setVisible(false);
        jGameInfo.setVisible(true);
        jHighScores.setVisible(false);
        jEditQuestions.setVisible(false);
}

    private void jEditTriviaActionPerformed(ActionEvent evt) {
    	if (isPlaying("Can't edit questions while playing!"))
    		return;
    	
        jMainMenu.setVisible(false);
        jEditQuestions.setVisible(true);
        edp.setVisible(true);
        jscroll.setVisible(true);
        this.setSize(800, 600);
        
        edp.refreshQuestions();
        jEditContainer.validate();
        jEditContainer.repaint();

}

    private void jHighScoresTriviaActionPerformed(ActionEvent evt) {//GEN-FIRST:event_jHighScoresTriviaActionPerformed
    	if (isPlaying("Can't view HighScores while playing"))
    		return;
    	
        jMainMenu.setVisible(false);
        jHighScores.setVisible(true);
}
    
    private boolean isPlaying(String msg) {
    	if (jGameInfo.isVisible() || jQuestions.isVisible() || jResults.isVisible()) {
    		showCantPlayDialog(msg);
    		return true;
    	}
    	
    	return false;
    }
    private void jComboBox1ActionPerformed(ActionEvent evt) {
        String[] titleString = {"Easy - HighScores", "Medium - HighScores",
                                "Hard - HighScores"};

        jTitleHscore.setText(titleString[jComboBox1.getSelectedIndex()]);
        displayScores();
                    
    }

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
        jNewTriviaActionPerformed(evt);
        return;
    }
    
    private void jMenuItem2ActionPerformed(ActionEvent evt) {
        System.exit(0);
    }

    private void jMenuItem3ActionPerformed(ActionEvent evt) {
    	jEditTriviaActionPerformed(evt);
    	return;
    }
    
    private void jMenuItem4ActionPerformed(ActionEvent evt) {
       	jHighScoresTriviaActionPerformed(evt);
       	return;
    }

    private void jExitScoresActionPerformed(ActionEvent evt) {
        jHighScores.setVisible(false);
        jMainMenu.setVisible(true);
    }

    private void jQNextActionPerformed(ActionEvent evt) throws TriviaException, IOException {
        
    	/**
    	 * Analiza las componentes del panel de preguntas,
    	 * cuando detecta que es 1, significa que es un campo
    	 * de texto. La pregunta puede ser de tipo numerica
    	 * o de texto simple, por ende si es una o la otra
    	 * setea la respuesta final del usuario. 
    	 */
    	if (jQOptions.getComponentCount() == 1) {
    		JTextField jtxt = (JTextField)jQOptions.getComponent(0);
    		if (q instanceof NumericQuestion) {
    			NumericQuestion auxq = (NumericQuestion) q;
    			try {
    				auxq.setUsrAns(Double.valueOf(jtxt.getText()));
    			} catch (NumberFormatException n){
    				auxq.setUsrAns(null);
    			}
    		} else {
    			SimpleQuestion auxq = (SimpleQuestion) q;
    			auxq.setUsrAns(jtxt.getText());
    		}
    			
    	}
    	
    	// Quita todos los componentes inherentes a la pregunta anterior
        jQOptions.removeAll();
        jQOptions.repaint();

        if (q.validAnswer()) {
            guser.addScore(q.getScore());
            correctAnswers[qnumber++] = true;
        } else {
            correctAnswers[qnumber++] = false;
        }

        if (qiter.hasNext()) {
            displayQuestion(qiter);
        } else {
        	qnumber = 0;
            displayResults(guser);
        }

        return;
    }

    private void jMenu1ActionPerformed(ActionEvent evt) {
        jNewTriviaActionPerformed(evt);
    }

    private void jInputNameActionPerformed(ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void jStartGameActionPerformed(ActionEvent evt) {
        try {
                String name;
                name = jInputName.getText();
                name = name.trim();

            if (name.length() == 0) {
                jWarning.setText("Name field cannot be empty!");
                return;
            }

            if (name.contains(" ")) {
            	jWarning.setText("Spaces are not allowed!");
            	return;
            }
            // Carga los datos de la partida
            jWarning.setText("");

            guser = new database.GameUser(name);
            guser.setCurrlevel(jLevel.getSelectedIndex());
            guser.setQuestions(tdbase.getTriviaQuestions(guser.getCurrlevel()));
            
            for (Question q : guser.getQuestions())
            	resetUsrAnswers(q);

        } catch (TriviaException ex) {
            // MARK
            jWarning.setText("");
            try {
                guser = new database.GameUser("Unknown");
            } catch (TriviaException ex1) {
                // No se hace nada porque ya sabemos que no tira exception
            }
            try {
                guser.setCurrlevel(jLevel.getSelectedIndex());
                guser.setQuestions(tdbase.getTriviaQuestions(guser.getCurrlevel()));
            } catch (TriviaException ex1) {
                ex1.printStackTrace();
                System.exit(1);
            }
        } catch(NullPointerException e) {
        	showCantPlayDialog("Not enought Questions to play, edit trivia to add more");
        	jGameInfo.setVisible(false);
        	jMainMenu.setVisible(true);
        	return;
        }

        /**
         * Comienza el juego, extrae las 10 preguntas del cuestionario
         * e inicializa espacio para 10 boolean que representan si las preguntas
         * fueron contestadas bien o mal
         */
        jGameInfo.setVisible(false);
        jQuestions.setVisible(true);
        qiter = guser.getQuestions().iterator();
        correctAnswers = new Boolean[guser.getQuestions().size()];
        displayQuestion(qiter);
        return;
}//GEN-LAST:event_jStartGameActionPerformed

    private void resetUsrAnswers(Question q) {
    	if (q instanceof BooleanQuestion) {
    		((BooleanQuestion) q).setUsrAns(null);
    	} else if (q instanceof NumericQuestion) {
    		((NumericQuestion) q).setUsrAns(null);
    	} else if (q instanceof SimpleQuestion) {
    		((SimpleQuestion) q).setUsrAns("");
    	} else {
    		((MultipleQuestion)q).setUsrAns(null);
    	}
    	return ;
    }
    private void jGameCancelActionPerformed(ActionEvent evt) {
        jGameInfo.setVisible(false);
        jMainMenu.setVisible(true);
    }//GEN-LAST:event_jGameCancelActionPerformed

    private void jButton1ActionPerformed(ActionEvent evt) {
        jResults.setVisible(false);
        jAnswers.removeAll();
        jAnswers.validate();
        jHighScores.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jHighScoresComponentShown(java.awt.event.ComponentEvent evt) {
        displayScores();
    }//GEN-LAST:event_jHighScoresComponentShown

    private void jRadioButton1ActionPerformed(ActionEvent evt) throws TriviaException {
        LinkedList<Question> qlist = tdbase.getAllQuestions(0);
        edp.setQlist(qlist);
        edp.refreshQuestions();
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton2ActionPerformed(ActionEvent evt) throws TriviaException {
        LinkedList<Question> qlist = tdbase.getAllQuestions(1);
        edp.setQlist(qlist);
        edp.refreshQuestions();
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jRadioButton3ActionPerformed(ActionEvent evt) throws TriviaException {
        LinkedList<Question> qlist = tdbase.getAllQuestions(2);
        edp.setQlist(qlist);
        edp.refreshQuestions();
    }//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jPageBackActionPerformed(ActionEvent evt) {
        edp.backPage();
    }//GEN-LAST:event_jPageBackActionPerformed

    private void jNextPageActionPerformed(ActionEvent evt) {
        edp.nextPage();
    }//GEN-LAST:event_jNextPageActionPerformed

    private void jEditFinishActionPerformed(ActionEvent evt) {
    	jEditQuestions.setVisible(false);
        jMainMenu.setVisible(true);
    }

    private void jEraseQuestionActionPerformed(ActionEvent evt) {
        Question qaux;
    	qaux = edp.removeQuestion(edp.getQuestionSelected());
    	
    	if (qaux != null) {
    		tdbase.removeQuestion(qaux);
    	}
    }

    private void jEditQuestionActionPerformed(ActionEvent evt, Question liveQ) {
    	liveEditq = liveQ;
        jEditQuestions.setVisible(false);
        
        
        if (liveEditq instanceof BooleanQuestion) {
        	jBoolMod.setVisible(true);
        	auxBool = new BooleanQuestion(false);
        	renderQuestionInfo((BooleanQuestion)liveEditq);
        } else if (liveEditq instanceof NumericQuestion) {
        	jNumMod.setVisible(true);
        	auxNum = new NumericQuestion(0);
        	renderQuestionInfo((NumericQuestion)liveEditq);
        } else if (liveEditq instanceof SimpleQuestion) {
        	jSimpleMod.setVisible(true);
        	auxSim = new SimpleQuestion(null);
        	renderQuestionInfo((SimpleQuestion)liveEditq);
        } else {
        	jMulti1Mod.setVisible(true);
        	auxMul = new MultipleQuestion(null, null);
        	renderQuestionInfo((MultipleQuestion)liveEditq);
        }
        
        return;
        
    }

    private void jMulti1AddActionPerformed(ActionEvent evt) {
    	DefaultListModel dlm;
        
    	dlm = (DefaultListModel)jMulti1List1.getModel();
    	
    	String s = (String)JOptionPane.showInputDialog(jMulti1Mod, 
    			"Set new option text",
    			"Add new option",
    			JOptionPane.OK_CANCEL_OPTION, 
    			null, 
    			null, 
    			null);

    	if (s != null && s.length() > 0) {
    		dlm.addElement(s);
    	}
    }

    private void jMulti1ModifyActionPerformed(ActionEvent evt) {
        DefaultListModel dlm1, dlm2;
        int index;
        
    	dlm1 = (DefaultListModel)jMulti1List1.getModel();
    	dlm2 = (DefaultListModel)jMulti1List2.getModel();
        
        String s = (String)JOptionPane.showInputDialog(jMulti1Mod, 
    			"Set new text",
    			"Modify option",
    			JOptionPane.OK_CANCEL_OPTION, 
    			null, 
    			null, 
    			null);

    	if (s != null && s.length() > 0) {
    		index = jMulti1List1.getSelectedIndex();
    		
    		if (dlm2.contains(dlm1.get(index)))
    			dlm2.setElementAt(s, index);
    		
    		dlm1.setElementAt(s, index);
    	}

    }

    private void jMulti1MoveActionPerformed(ActionEvent evt) {
        String elem;
        DefaultListModel dlm1, dlm2;
        
    	dlm1 = (DefaultListModel)jMulti1List1.getModel();
    	dlm2 = (DefaultListModel)jMulti1List2.getModel();
        
        elem = (String) dlm1.get(jMulti1List1.getSelectedIndex());
        
        if (!dlm2.contains(elem))
        	dlm2.addElement(elem);
        jMulti1List1.validate();
        jMulti1List2.validate();
        
    }

    private void jMulti1DeleteActionPerformed(ActionEvent evt) {
    	DefaultListModel dlm1, dlm2;
    	dlm1 = (DefaultListModel)jMulti1List1.getModel();
    	dlm2 = (DefaultListModel)jMulti1List2.getModel();
    	boolean isInAnswers;
    	String elem;
    	
    	/* Si solo hay 2 elementos, no se pueden borrar pues no seria
    	 * una pregunta de opciones multiples
    	 */
    	
    	if (dlm1.getSize() == 2) {
    		// Aca deberia tirar dialog box
    		return;
    	}
    	elem = (String) dlm1.get(jMulti1List1.getSelectedIndex());
    	isInAnswers = dlm2.contains(elem);
    	
    	// Si hay 1 sola rta, y se la quiere borrar como opcion, no se puede
    	if (dlm2.getSize() == 1 && isInAnswers) {
    		// Aca tmb deberia tirar dialog box
    		return;
    	} else if (isInAnswers) {
    		dlm2.remove(dlm2.indexOf(elem));
    	}
    	
    	dlm1.remove(jMulti1List1.getSelectedIndex());
    	jMulti1List1.validate();
        jMulti1List2.validate();
    	return;
    }

    private void jMulti1DelAnsActionPerformed(ActionEvent evt) {
    	DefaultListModel dlm;
    	dlm = (DefaultListModel)jMulti1List2.getModel();
    	int index;
    	index = jMulti1List2.getSelectedIndex();
    	
    	if (dlm.size() == 1) {
    		// dialog box
    		return;
    	}
    	if (index != -1)
    		dlm.remove(index);
    	
    	jMulti1List1.validate();
        jMulti1List2.validate();
    	return;
    }

    private void jMulti1ComboActionPerformed(ActionEvent evt) {
    	/*
    	if (edp.getQuestionAmount() < 11) {
    		jMulti1Combo.setEnabled(false);
    	} else {
    		jMulti1Combo.setEnabled(true);
    	}
    	*/
    	
    	auxMul.setLevel(jSimpleCombo.getSelectedIndex());
    }

    private void jMulti1CancelActionPerformed(ActionEvent evt) {
    	jMulti1Mod.setVisible(false);
        jEditQuestions.setVisible(true);
    }
    
    private boolean jMulti1SaveActionPerformed(ActionEvent evt) throws IOException {
    	LinkedList<String> slist = new LinkedList<String>();
		String[] optaux = new String[1];
		int i, correct = 0;
		String score, opt;
		DefaultListModel dlm1, dlm2;
		
				
    	dlm1 = (DefaultListModel)jMulti1List1.getModel();
    	dlm2 = (DefaultListModel)jMulti1List2.getModel();
    	score = jMulti1Score.getText().trim();
    	
	    		
    	Integer[] ans = new Integer[dlm1.getSize()];
    	
    	for (i = 0 ; i < dlm1.getSize() ; i++) {
    		opt = (String)dlm1.get(i);
    		slist.add(opt);
    		ans[i] = 0;
    	}

    	String [] strans = new String[dlm2.getSize()];
    	
    	for (i = 0 ; i < dlm2.getSize() ; i++) {
    		strans[i] = (String)dlm2.get(i);
    	}
    	
        for (String s : strans) {
                
	        int index = slist.indexOf(s);
	        
	        if( index != -1 ) {
	                ans[index] = 1;
	                correct++;
	        }
                
        }
        
        if (validMulti1Components(dlm1, dlm2, correct)) {    
	    	auxMul.setOptions(slist.toArray(optaux));
	    	auxMul.setCorrect(ans);
	    	auxMul.setCorrectCount(correct);
	    	auxMul.setScore(Integer.valueOf(score));
	    	auxMul.setQuestionText(jMulti1QTxt.getText());
	    	saveChanges(auxMul);
	    	jMulti1Mod.setVisible(false);
	    	jEditQuestions.setVisible(true);
	    	return true;
    	}
    	
    	return false;
    }

    private boolean validMulti1Components(DefaultListModel dlm1, DefaultListModel dlm2,
    									  int correctQtty) {
    	String score, qtxt;
    	
    	score = jMulti1Score.getText().trim();
    	qtxt = jMulti1QTxt.getText().trim();
		
    	if (Integer.valueOf(score) > 0 && qtxt.length() > 0 && 
    		dlm1.getSize() > 1 && dlm2.getSize() > 0 && correctQtty > 0)
    			return true;
    	
    	return false;
    }
    
    private void jSimpleComboActionPerformed(ActionEvent evt) {
    	/*
    	if (edp.getQuestionAmount() < 11) {
    		jSimpleCombo.setEnabled(false);
    	} else {
    		jSimpleCombo.setEnabled(true);
    	}
		*/
    	auxSim.setLevel(jSimpleCombo.getSelectedIndex());
        return;
    }

    private void jSimpleCancelActionPerformed(ActionEvent evt) {
    	jSimpleMod.setVisible(false);
        jEditQuestions.setVisible(true);
        return;
    }
    
    private boolean jSimpleSaveActionPerformed(ActionEvent evt) throws IOException {
    	String score;
    	
    	if (validSimpleContents()) {
    	
			score = jSimpleScore.getText().trim();
	    	 
	    	auxSim.setQuestionText(jSimpleQTxt.getText().trim());
	    	auxSim.setAnswer(jSimpleAnswer.getText().trim());
	    	auxSim.setScore(Integer.valueOf(score));
	    	saveChanges(auxSim);
	    	jSimpleMod.setVisible(false);
	    	jEditQuestions.setVisible(true);
	    	return true;
    	}
	    
    	
    	return false;
    }

    private boolean validSimpleContents() {
    	String qtxt, score, ans;
    	
    	qtxt = jSimpleQTxt.getText().trim();
    	score = jSimpleScore.getText().trim();
    	ans = jSimpleAnswer.getText().trim();
    	
    	if (qtxt.length() > 0 && Integer.valueOf(score) > 0 && ans.length() > 0)
    		return true;
    	
        return false;
        
    }
    
    private void jNumComboActionPerformed(ActionEvent evt) {
    	/*
    	if (edp.getQuestionAmount() < 11) {
    		jNumCombo.setEnabled(false);
    	} else {
    		jNumCombo.setEnabled(true);
    	}
    	*/
    	
    	auxNum.setLevel(jNumCombo.getSelectedIndex());
        return;
    }
    
    private void jNumCancelActionPerformed(ActionEvent evt) {
    	jNumMod.setVisible(false);
        jEditQuestions.setVisible(true);
        return;
    }
    
    private boolean jNumSaveActionPerformed(ActionEvent evt) throws IOException {
    	String score;
    	
    	if (validNumContents()) {
    	
			score = jNumScore.getText().trim();
			
			auxNum.setQuestionText(jNumQTxt.getText().trim());
	    	auxNum.setAnswer(Double.valueOf(jNumAnswer.getText().trim()));
	    	auxNum.setScore(Integer.valueOf(score));
	    	saveChanges(auxNum);
	    	
	    	jNumMod.setVisible(false);
	    	jEditQuestions.setVisible(true);
	    	return true;
    	}
    	
    	return false;
    }

    private boolean validNumContents() {
    	String qtxt, score, ans;
    	
    	qtxt = jNumQTxt.getText().trim();
    	score = jNumScore.getText().trim();
    	ans = jNumAnswer.getText().trim();
    	
    	if (qtxt.length() > 0 && Integer.valueOf(score) > 0 && 
    		Double.valueOf(ans) > 0)
    			return true;
    	
        return false;
        
    }
    
    
    private void jBoolQTrueActionPerformed(ActionEvent evt) {
        auxBool.setAnswer(true);
        return;
    }

    private void jBoolQFalseActionPerformed(ActionEvent evt) {
        auxBool.setAnswer(false);
        return;
    }

    private void jBoolComboActionPerformed(ActionEvent evt) {
    	/*
    	if (edp.getQuestionAmount() < 11) {
    		jBoolCombo.setEnabled(false);
    	} else {
    		jBoolCombo.setEnabled(true);
    	}
    	*/
    	
    	auxBool.setLevel(jBoolCombo.getSelectedIndex());
        return;
    }

    private void jBoolCancelActionPerformed(ActionEvent evt) {
        jBoolMod.setVisible(false);
        jEditQuestions.setVisible(true);
        return;
    }
    
    private boolean jBoolSaveActionPerformed(ActionEvent evt) throws IOException {
    	String score;
    	
    	if (validBoolContents()) {
    	
			score = jBoolScore.getText().trim();
			
			auxBool.setQuestionText(jBoolQTxt.getText().trim());
	    	auxBool.setScore(Integer.valueOf(score));
	    	saveChanges(auxBool);
	    	jBoolMod.setVisible(false);
	    	jEditQuestions.setVisible(true);
	    	return true;
    	}
    	
    	return false;
    }

    private boolean validBoolContents() {
    	String qtxt, score;
    	
    	qtxt = jBoolQTxt.getText().trim();
    	score = jBoolScore.getText().trim();
    	
    	if (qtxt.length() > 0 && Integer.valueOf(score) > 0)
    			return true;
    	
        return false;
    }
    
    private void saveChanges(Question q) throws IOException {
    	// Diferencia la edicion del agregado de una nueva pregunta
    	if (liveEditq == edp.getQuestionSelected()) {
	    	tdbase.removeQuestion(liveEditq);
	    	tdbase.newQuestion(q);
	    	
	    	// Agrega la pregunta al panel, lo cual lo refreshea
	    	if (q.getLevel() == liveEditq.getLevel()) {
	    		edp.addQuestion(q);
	    	}
	    	
	    	edp.removeQuestion(liveEditq);
        } else {
        	tdbase.newQuestion(q);
        	edp.addQuestion(q);
        }
    	
    	// Nueva pregunta, se salva la base de datos!
    	tdbase.saveQuestions();
    	edp.refreshQuestions();
    	return;
    }
    
    private void jNewQuestionActionPerformed(ActionEvent evt) {
    	Object[] choices = {"Boolean Question", "Numeric Question",
    					  "Simple Text Question", "Multiple Choice Question"};
    	
    	String qtype = (String)JOptionPane.showInputDialog(jEditQuestions, 
    			"Choose question type",
    			"Add new question",
    			JOptionPane.PLAIN_MESSAGE,
    			null,
    			choices,
    			choices[0]);
    	
    	int chosen = 4; // no question type chosen
    	
    	for (int i = 0 ; i < choices.length ; i++) {
    		if (choices[i].equals(qtype))
    			chosen = i;
    	}
    	
    	switch(chosen) {
    		case 0:
    				BooleanQuestion bq = new BooleanQuestion(true);
    				jBoolCombo.setEnabled(true);
    				jEditQuestionActionPerformed(evt, bq);
    				break;
    		case 1:
    				NumericQuestion nq = new NumericQuestion(0);
    				jNumCombo.setEnabled(true);
    				jEditQuestionActionPerformed(evt, nq);
    				break;
    		case 2:
    				SimpleQuestion sq = new SimpleQuestion(null);
    				jSimpleCombo.setEnabled(true);
    				jEditQuestionActionPerformed(evt, sq);
    				break;
    		case 3:
    				MultipleQuestion mq = new MultipleQuestion(null, null);
    				jMulti1Combo.setEnabled(true);
    				jEditQuestionActionPerformed(evt, mq);
    				break;
    		default:
    				return;
    	}
    	
    	return;

    }

    private void renderQuestionInfo(BooleanQuestion q) {
    	String qtxt;
    	boolean ans;
    	
    	qtxt = q.getQuestionText();
    	ans = q.getAnswer();
    	
    	if (qtxt != null && qtxt.length() > 0) {
	    	jBoolQTxt.setText(qtxt);
	    	jBoolQTrue.setSelected(ans);
	    	jBoolQFalse.setSelected(!ans);
	    	jBoolScore.setText(String.valueOf(q.getScore()));
	    	jBoolCombo.setSelectedIndex(q.getLevel());
    	} else {
    		jBoolQTxt.setText("");
	    	jBoolQTrue.setSelected(ans);
	    	jBoolQFalse.setSelected(!ans);
	    	jBoolScore.setText("0");
	    	jBoolCombo.setSelectedIndex(0);
    	}
    	return;
    }
    
    private void renderQuestionInfo(NumericQuestion q) {
    	String qtxt, ans;
    	
    	qtxt = q.getQuestionText();
    	ans = String.valueOf(q.getAnswer());
    	
    	if (qtxt != null && qtxt.length() > 0 ) {
	    	jNumQTxt.setText(qtxt);
	    	jNumAnswer.setText(ans);
	    	jNumScore.setText(String.valueOf(q.getScore()));
	    	jNumCombo.setSelectedIndex(q.getLevel());
    	} else {
    		jNumQTxt.setText("");
	    	jNumAnswer.setText("");
	    	jNumScore.setText("0");
	    	jNumCombo.setSelectedIndex(0);
    	}
    	return;
    }
    
    private void renderQuestionInfo(SimpleQuestion q) {
    	String qtxt, ans;
    	
    	qtxt = q.getQuestionText();
    	ans = q.getAnswer();
    	
    	if (qtxt != null && qtxt.length() > 0 && ans != null
    		&& ans.length() > 0) {
	    	jSimpleQTxt.setText(qtxt);
	    	jSimpleAnswer.setText(ans);
	    	jSimpleScore.setText(String.valueOf(q.getScore()));
	    	jSimpleCombo.setSelectedIndex(q.getLevel());
    	} else {
    		jSimpleQTxt.setText("");
	    	jSimpleAnswer.setText("");
	    	jSimpleScore.setText("0");
	    	jSimpleCombo.setSelectedIndex(0);
    	}
    	return;
    }
    
    private void renderQuestionInfo(MultipleQuestion q) {
    	jMulti1QTxt.setText(q.getQuestionText());
    	DefaultListModel dlm1, dlm2;
    	Integer[] ans;
    	int i, j;
    	
    	jMulti1List1.setModel(new DefaultListModel());
    	jMulti1List2.setModel(new DefaultListModel());
    	
    	dlm1 = (DefaultListModel)jMulti1List1.getModel();
    	dlm2 = (DefaultListModel)jMulti1List2.getModel();
    	ans = q.getCorrect();
    	
    	 i = j = 0;
    	
    	if (ans != null && q.getOptions() != null) {
	    	for (String opt : q.getOptions()) {
	    		if (i < ans.length && ans[i].equals(1)) {
	    			dlm2.add(j++, opt);
	    		}
	    		dlm1.add(i++, opt);
	    	}
    	
	    	jMulti1Score.setText(String.valueOf(q.getScore()));
    		jMulti1Combo.setSelectedIndex(q.getLevel());
    	} else {
    		jMulti1Score.setText("0");
    		jMulti1Combo.setSelectedIndex(0);
    	}
    	return;
    }
    private void initHighScores() throws NumberFormatException, TriviaException {

    	// Carga los highscore de los archivos a la base de datos
    	tdbase.loadHighScores();
    	jScoreTable.setEnabled(false);
        displayScores();
    }

    private void displayScores() {
        Score[] highscores = null;
        highscores = tdbase.getHighScoresByLevel(jComboBox1.getSelectedIndex());
        int i, j;

        i = j = 0;
        
        // La primera ejecucion del programa, tendra highscores vacios
        if (highscores != null) {
	        for (Score scores : highscores) {
	            jScoreTable.setValueAt(scores.getUser(), i, j++);
	            jScoreTable.setValueAt(Integer.toString(scores.getScore()) + "%", i++, j);
	            j = 0;
	        }
        } else {
        	for (i = 0, j = 0; i < 10 ; i++) {
	            jScoreTable.setValueAt("", i, j++);
	            jScoreTable.setValueAt("", i, j);
	            j = 0;
	        }
        }

        
    }

    private void displayQuestion(Iterator<Question> qiter) {
        //Question q;
        q = (Question)qiter.next();
        jQtext.setText("<HTML>" + q.getQuestionText() + "</HTML>");
        q.accept(qvisitor);
        jQOptions.validate();
        jQOptions.repaint();
    }

    private void displayResults(GameUser guser) throws TriviaException, IOException {
    	jQuestions.setVisible(false);
        
        buildResults(guser);
        jResults.setVisible(true);
    }

    private void buildResults(GameUser guser) throws TriviaException, IOException {
        LinkedList<Question> questionary;
        int qcount;
        ImageIcon right, wrong;
        Score scr;

        right = new ImageIcon(getClass().getResource(
                "/datagraphics/tick_green2.png"));

        wrong = new ImageIcon(getClass().getResource(
                "/datagraphics/incorrect2.png"));

        questionary = guser.getQuestions();
        qcount = questionary.size();

        JLabel[] qstr = new JLabel[qcount];
        
        for (int i = 0 ; i < qcount ; i++) {
            qstr[i] = new JLabel(questionary.get(i).getQuestionText());
            if (correctAnswers[i]) {
                qstr[i].setIcon(right);
            } else {
                qstr[i].setIcon(wrong);
            }
            
            jAnswers.add(qstr[i]);
        }
        
        scr = guser.getGameResults();
        tdbase.trySetNewScore(guser.getCurrlevel(), scr);
        
        jFinalScore.setText(String.valueOf(scr.getScore()) + "%");
        jAnswers.validate();
        jAnswers.repaint();

    }
    
    private void showCantPlayDialog(String msg) {
    	JOptionPane.showConfirmDialog(this, (Object)msg, "Trivia Error",
    										JOptionPane.OK_CANCEL_OPTION,
    										JOptionPane.ERROR_MESSAGE);
    	return;
    }

    private void initEditPanel() throws NullPointerException, TriviaException {
    	edp = new EditPanel(tdbase.getAllQuestions(0));
        jscroll = new JScrollPane(edp, 
        		ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
        		ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    	edp.setSize(550, 350);
    	edp.setAutoscrolls(true);
        edp.setPreferredSize(new Dimension(550,350));
    	jEditQuestions.setSize(640, 480);
        jscroll.setSize(jEditContainer.getSize());
        jEditContainer.add(jscroll);
        return;
    }
    
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
					new MainMenu().setVisible(true);
				} catch (TriviaException e) {
					e.printStackTrace();
				} catch (NumberFormatException e) {
//					 TODO Bloque catch generado autom�ticamente
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

            }
        });
    }

    // CODE GENERATED BY NETBEANS
    private javax.swing.ButtonGroup BooleanAnswer;
    private javax.swing.ButtonGroup EditCategory;
    private javax.swing.JPanel jAnswerContainer;
    private javax.swing.JPanel jAnswers;
    private javax.swing.JButton jBoolCancel;
    private javax.swing.JComboBox jBoolCombo;
    private javax.swing.JInternalFrame jBoolMod;
    private javax.swing.JRadioButton jBoolQFalse;
    private javax.swing.JRadioButton jBoolQTrue;
    private javax.swing.JTextField jBoolQTxt;
    private javax.swing.JButton jBoolSave;
    private javax.swing.JFormattedTextField jBoolScore;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JPanel jEditContainer;
    private javax.swing.JButton jEditFinish;
    private javax.swing.JButton jEditQuestion;
    private javax.swing.JInternalFrame jEditQuestions;
    private javax.swing.JButton jEditTrivia;
    private javax.swing.JButton jEraseQuestion;
    private javax.swing.JButton jExitScores;
    private javax.swing.JLabel jFinalScore;
    private javax.swing.JButton jGameCancel;
    private javax.swing.JInternalFrame jGameInfo;
    private javax.swing.JInternalFrame jHighScores;
    private javax.swing.JButton jHighScoresTrivia;
    private javax.swing.JFormattedTextField jInputName;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JComboBox jLevel;
    private javax.swing.JInternalFrame jMainMenu;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JButton jMulti1Add;
    private javax.swing.JButton jMulti1Cancel;
    private javax.swing.JComboBox jMulti1Combo;
    private javax.swing.JButton jMulti1DelAns;
    private javax.swing.JButton jMulti1Delete;
    private javax.swing.JList jMulti1List1;
    private javax.swing.JList jMulti1List2;
    private javax.swing.JInternalFrame jMulti1Mod;
    private javax.swing.JButton jMulti1Modify;
    private javax.swing.JButton jMulti1Move;
    private javax.swing.JTextField jMulti1QTxt;
    private javax.swing.JButton jMulti1Save;
    private javax.swing.JFormattedTextField jMulti1Score;
    private javax.swing.JButton jNewQuestion;
    private javax.swing.JButton jNewTrivia;
    private javax.swing.JButton jNextPage;
    private javax.swing.JFormattedTextField jNumAnswer;
    private javax.swing.JButton jNumCancel;
    private javax.swing.JComboBox jNumCombo;
    private javax.swing.JInternalFrame jNumMod;
    private javax.swing.JTextField jNumQTxt;
    private javax.swing.JButton jNumSave;
    private javax.swing.JFormattedTextField jNumScore;
    private javax.swing.JButton jPageBack;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jQBoolean;
    private javax.swing.JPanel jQMultiple;
    private javax.swing.JButton jQNext;
    private javax.swing.JPanel jQNum;
    private javax.swing.JPanel jQOptions;
    private javax.swing.JPanel jQSimple;
    private javax.swing.JLabel jQtext;
    private javax.swing.JPanel jQuestionPane;
    private javax.swing.JInternalFrame jQuestions;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JInternalFrame jResults;
    private javax.swing.JTable jScoreTable;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JTextField jSimpleAnswer;
    private javax.swing.JButton jSimpleCancel;
    private javax.swing.JComboBox jSimpleCombo;
    private javax.swing.JInternalFrame jSimpleMod;
    private javax.swing.JTextField jSimpleQTxt;
    private javax.swing.JButton jSimpleSave;
    private javax.swing.JFormattedTextField jSimpleScore;
    private javax.swing.JButton jStartGame;
    private javax.swing.JLabel jTitleHscore;
    private javax.swing.JLabel jUsrInfoImg;
    private javax.swing.JLabel jUsrName;
    private javax.swing.JLabel jWarning;
    // End of variables declaration//GEN-END:variables

}
